package com.supms.course.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.supms.course.domain.TestReview;
import com.supms.course.service.ITestReviewService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 本科试卷复查Controller
 * 
 * @author LiangHao
 * @date 2022-03-08
 */
@RestController
@RequestMapping("/testReview")
public class TestReviewController extends BaseController
{
    @Autowired
    private ITestReviewService testReviewService;

    /**
     * 查询本科试卷复查列表
     */
    @RequiresPermissions("course:testReview:list")
    @GetMapping("/list")
    public TableDataInfo list(TestReview testReview)
    {
        startPage();
        List<TestReview> list = testReviewService.selectTestReviewList(testReview);
        return getDataTable(list);
    }

    /**
     * 导出本科试卷复查列表
     */
    @RequiresPermissions("course:testReview:export")
    @Log(title = "本科试卷复查", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestReview testReview)
    {
        List<TestReview> list = testReviewService.selectTestReviewList(testReview);
        ExcelUtil<TestReview> util = new ExcelUtil<TestReview>(TestReview.class);
        util.exportExcel(response, list, "本科试卷复查数据");
    }

    /**
     * 获取本科试卷复查详细信息
     */
    @RequiresPermissions("course:testReview:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(testReviewService.selectTestReviewById(id));
    }

    /**
     * 新增本科试卷复查
     */
    @RequiresPermissions("course:testReview:add")
    @Log(title = "本科试卷复查", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestReview testReview)
    {
        return toAjax(testReviewService.insertTestReview(testReview));
    }

    /**
     * 修改本科试卷复查
     */
    @RequiresPermissions("course:testReview:edit")
    @Log(title = "本科试卷复查", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestReview testReview)
    {
        return toAjax(testReviewService.updateTestReview(testReview));
    }

    /**
     * 删除本科试卷复查
     */
    @RequiresPermissions("course:testReview:remove")
    @Log(title = "本科试卷复查", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        int i = testReviewService.deleteTestReviewByIds(ids);
        if (i == 5000) {
            return error("删除失败！当前试卷复查表下有错误成绩登记。");
        } else return toAjax(i);
    }


    /**
     * 获取本科试卷复查表（数据综合查看表）
     */
    @GetMapping("/getTestReviewTable")
    public TestReview getTestReviewTable(TestReview testReview)
    {
        return testReviewService.getTestReviewTable(testReview);
    }
}
